home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdlib.h>
- #include <ctype.h>
-
- #include "NString.h"
- #include "NString_Misc.h"
-
- //_________________________________________________________________________________
-
- NString NString::upcase (void) const
- {
- unsigned long int i;
- NString result(sb->len);
-
- if (sb->len == 0)
- return (*this);
-
- for (i=0; i < sb->len; i++)
- result.sb->str[i] = toupper(sb->str[i]);
-
- return (result);
- }
-
- //_________________________________________________________________________________
-
- NString NString::lowcase (void) const
- {
- unsigned long int i;
- NString result(sb->len);
-
- if (sb->len == 0)
- return (*this);
-
- for (i=0; i < sb->len; i++)
- result.sb->str[i] = tolower(sb->str[i]);
-
- return (result);
- }
-
- //_________________________________________________________________________________
-
- NString& NString::toupcase (void)
- {
- unsigned long int i;
-
- if (sb->len == 0)
- return *this;
-
- if (sb->refs > 1) // the string body is used by another NString: must duplicate it to prevent
- if (! DuplicateSB()) // changes in common body
- OUT_OF_MEM("toupcase (void)");
-
- for (i=0; i < sb->len; i++)
- sb->str[i] = toupper(sb->str[i]);
-
- return *this;
- }
-
- //_________________________________________________________________________________
-
- NString& NString::tolowcase (void)
- {
- unsigned long int i;
-
- if (sb->len == 0)
- return *this;
-
- if (sb->refs > 1) // the string body is used by another NString: must duplicate it to prevent
- if (! DuplicateSB()) // changes in common body
- OUT_OF_MEM("tolowcase (void)");
-
- for (i=0; i < sb->len; i++)
- sb->str[i] = tolower(sb->str[i]);
-
- return *this;
- }
-
- //_________________________________________________________________________________
-
- NString& NString::clear (void)
- {
- const char *fname = "clear (void)";
-
- if (sb->len == 0)
- return *this;
-
- if (sb->refs > 1)
- {
- if (! GetNewSB(0)) // Get a new string body & inscribe terminating NUL and new length
- OUT_OF_MEM(fname);
-
- return *this;
- }
-
- if (! ReallocStrBuf(0)) // Resize the current string body's buffer
- OUT_OF_MEM(fname);
-
- sb->str[0] = '\0'; // Terminate the new (empty) string
- sb->len = 0; // Inscribe new length
- return *this;
- }
-